/*
 * User: user
 * Date: 20/12/2007
 * Time: 09:00:11
 */
package org.conann.metadata.validation;

import org.conann.metadata.records.Record;

import javax.webbeans.binding.New;

public abstract class RecordValidator<T extends Record<?>> {

    public abstract void validate(T record);

    protected void checkNewAnnotationComesAlone(T record) {
        if (record.isAnnotatedBy(New.class)) {
            check(record.getAllAnnotations().size() == 1, "{0} is annotated with @{1} annotation, but has other binding annotations as well. @{1} annotation must be specified alone.", record.getElement(), New.class);
        }
    }

    protected void check(boolean predicate, String message, Object... messageParams) {
        if (!predicate) {
            throw new WebBeansValidationException(message, messageParams);
        }
    }
}